﻿/**
 * Created by Administrator on 2017/3/1 0001.
 */
var Preload=
{
    create:function()
    {
        var page={};

        var loader_pre=new PIXI.loaders.Loader();
        var arr_assetsPre=[];
        arr_assetsPre.push(
        );
        var loader=new PIXI.loaders.Loader();


        var graphic_bg,graphic_loadingBottom,graphic_loading;
        var text_progress;
        var sp_logo;



        var arr_assets=[];
        arr_assets.push(
            'assets/images/p0_t0.png',
            'assets/images/p0_t1.png',
            'assets/images/p0_t2.png',
            'assets/images/p1_clock.png',
            'assets/images/p1_m.png',
            'assets/images/p1_h.png',
            'assets/images/p1_center.png',
            'assets/images/p1_frame.png',
            'assets/images/p1_hand.png',
            'assets/images/p1_tip.png',
            'assets/images/p2_i00.png',
            'assets/images/p2_i01.png',
            'assets/images/p2_i10.png',
            'assets/images/p2_i11.png',
            'assets/images/p2_i20.png',
            'assets/images/p2_i21.png',
            'assets/images/p2_i30.png',
            'assets/images/p2_i31.png',
            'assets/images/p2_i40.png',
            'assets/images/p2_i41.png',
            'assets/images/p2_line.png',
            'assets/images/p2_t00.png',
            'assets/images/p2_t01.png',
            'assets/images/p2_t10.png',
            'assets/images/p2_t11.png',
            'assets/images/p2_t20.png',
            'assets/images/p2_t21.png',
            'assets/images/p2_t30.png',
            'assets/images/p2_t31.png',
            'assets/images/p2_t40.png',
            'assets/images/p2_t41.png',
            'assets/images/p3_bg.png',
            'assets/images/p3_hand.png',
            'assets/images/p3_hat.png',
            'assets/images/p3_t0.png',
            'assets/images/p3_tip.png',
            'assets/images/p4_bg.png',
            'assets/images/p4_hand.png',
            'assets/images/p4_t0.png',
            'assets/images/p4_teapot.png',
            'assets/images/p4_tip.png',
            'assets/images/p5_bg.png',
            'assets/images/p5_hand.png',
            'assets/images/p5_t0.png',
            'assets/images/p5_tip.png',
            'assets/images/p5_flower.png',
            'assets/images/p6_t0.png',
            'assets/images/p6_tip.png',
            'assets/images/p6_bg.png',
            'assets/images/p6_cover.png',
            'assets/images/p6_hand.png',
            'assets/images/p6_curtain.png',
            'assets/images/p7_bg.png',
            'assets/images/p7_bg1.png',
            'assets/images/p7_moon.png',
            'assets/images/p7_t0.png',
            'assets/images/p7_tip.png',
            'assets/images/p7_hand.png',
            'assets/images/p8_circle.png',
            'assets/images/p8_flower.png',
            'assets/images/p8_t0.png',
            'assets/images/p8_t1.png',
            'assets/images/p9_t0.png',
            'assets/images/p9_t1.png',
            'assets/images/p9_i0.png',
            'assets/images/p9_i1.png',
            'assets/images/p10_bg.png',
            'assets/images/p10_i1.png',
            'assets/images/p10_i2.png',
            'assets/images/p10_logo.png',
            'assets/images/p10_logo2.png',
            'assets/images/p10_t0.png',
            'assets/images/p10_t1.png',
            'assets/images/p10_tt2.png',
            'assets/images/p10_tt3.png',
            'assets/images/p10_t4.png',
            'assets/images/p10_line.png',
            'assets/images/p2_glowLine.png',
            'assets/images/tip1.png',
            'assets/images/p12_logo.png'

        );
        for(var i=0;i<43;i++)
        {
            if(i<10)
            {
                arr_assets.push('assets/images/01/Show.0'+i.toString()+'.jpg')
            }
            else
            {
                arr_assets.push('assets/images/01/Show.'+i.toString()+'.jpg')
            }

        }

        loader.add(arr_assets)
            .on("progress", loadProgressHandler)
            .load(completeHandler);
        function loadProgressHandler(loader, resource)
        {
            text_progress.text=Math.floor(loader.progress)+"%";
            graphic_loading.scale.x=loader.progress/100;
        }
        function completeHandler()
        {
            console.log('cccccccccc')
            var event = new CustomEvent("Main_LoadComplete", {detail:loader });
            document.dispatchEvent(event);
            TweenMax.to(graphic_bg,1,{alpha:0});
            TweenMax.to(sp_logo,1,{y:sp_logo.y-100,alpha:0,ease:Cubic.easeInOut});
            TweenMax.to(graphic_loading,1,{y:graphic_loading.y+100,alpha:0,ease:Cubic.easeInOut});
            TweenMax.to(graphic_loadingBottom,1,{y:graphic_loadingBottom.y+100,alpha:0,ease:Cubic.easeInOut});
            TweenMax.to(text_progress,1,{y:text_progress.y+100,alpha:0,ease:Cubic.easeInOut});
        }
        page.init=function(stage,stageW,stageH)
        {
            graphic_bg = new PIXI.Graphics();
            graphic_bg.beginFill(0x0);
            graphic_bg.drawRect(0,0,stageW,stageH);
            stage.addChild(graphic_bg);

            graphic_loadingBottom=new PIXI.Graphics();
            graphic_loadingBottom.beginFill(0xcccccc);
            graphic_loadingBottom.drawRect(0,0,300,2);
            graphic_loadingBottom.x=(stageW-graphic_loadingBottom.width)/2;
            graphic_loadingBottom.y=(stageH/2)+40;
            stage.addChild(graphic_loadingBottom);

            graphic_loading=new PIXI.Graphics();
            graphic_loading.beginFill(0xff6600);
            graphic_loading.drawRect(0,0,300,2);
            graphic_loading.x=(stageW-graphic_loading.width)/2;
            graphic_loading.y=(stageH/2)+40;
            graphic_loading.scale.x=0;
            stage.addChild(graphic_loading);

            sp_logo=new PIXI.Sprite.fromImage('assets/images/创邑_LOGO.png');
            sp_logo.anchor.set(0.5);
            sp_logo.scale.x=sp_logo.scale.y=0.6;
            sp_logo.x=stageW/2;
            sp_logo.y=stageH/2-10;
            stage.addChild(sp_logo);

            text_progress= new PIXI.Text('0%',{fontFamily : 'Arial', fontSize: 20, fill : 0xcccccc, align : 'center'});
            text_progress.anchor.x=0.5;
            text_progress.anchor.y=0.5;
            text_progress.x = stageW/2;
            text_progress.y = stageH/2+80;
            stage.addChild(text_progress);
        }

        return page;
    }
}
